<template>
  <div>
    <custom-table
      :columns="columns"
      :query="queryParams"
      :row-btn="rowBtn"
      :show-head-btn="['flush','delete']"
      v-bind="$attrs"
      v-on="listeners"
      @tap-head-btn="onTapHeadBtn"
      @tap-row-btn="onTapRowBtn"
      @row-dblclick="onRowDbClick"
    >
    </custom-table>
  </div>

</template>

<script>
import tableMixin from '@/utils/mixin/custom-table'
import mock from '@/utils/mixin/mock'

var Mock = require('mockjs')
import { randomNum } from '@/utils'

export default {
  data() {
    return {
      columns: [
        { name: '房号', field: 'number', width: 150, type: 'tag' },
        { name: '租户', field: 'nickname', width: 150 },
        { name: '租金', field: 'amount', width: 150, after: '元' },
        { name: '日期', field: 'date', width: 150 },
        // { name: '状态', field: 'status', label: true, type: this.checkAuth('change') ? 'switch' : 'tag', opts: {} },
        { name: '状态', field: 'status', type: 'tag', opts: {} },
        { name: '添加时间', field: 'create_time', width: 150 }
      ]
    }
  },
  components: {},
  mixins: [
    tableMixin, mock
  ],
  computed: {
    rowBtn() {
      return [
        {
          name: '催收',
          key: 'notice',
          confirm: '确认进行发送催收通知吗？',
          show(row) {
            return row.status === '待缴费'
          }
        }
      ]
    }
  },
  props: {},
  filters: {},
  created() {
  },
  methods: {
    onLoad() {
      Mock.Random.extend({
        roomType(date) {
          return this.pick(['单间', '一房一厅', '两房一厅', '三房一厅', '豪华套房'])
        },
        area() {
          return randomNum(50, 200)
        },
        amount() {
          return randomNum(500, 2000)
        },
        buildingName(data) {
          return this.pick(['A栋', 'B栋', 'C栋', 'D栋']) + randomNum(1, 999).toString().padStart(3, '0')
        },
        status() {
          return this.pick(['待缴费', '已缴费'])
        },
        roomNo() {
          return '琼花湖' + randomNum(1, 10) + '栋' + randomNum(1, 999).toString().padStart(3, '0')
        }
      })
      var data = Mock.mock({
        // 属性 list 的值是一个数组，其中含有 1 到 10 个元素
        'list|20': [{
          // 属性 id 是一个自增数，起始值为 1，每次增 1
          'id|+1': 1,
          'number': '@roomno',
          'nickname': '@cname',
          'amount|500-1999': 1,
          'area': '@area',
          'amount': '@amount',
          'date': '@date',
          'create_time': '@now',
          'status': '@status',
          'room_type': '@roomtype',
          'name': '@buildingname'
        }]
      })

      console.log('mock', data)

      this.setMockData(data)
    }
  }
}
</script>

<style lang="scss">

</style>
